package com.sofwin.service.impl.contents;

import com.sofwin.dto.HorizontalDto;
import com.sofwin.mapper.CBriefrelationshipMapper;
import com.sofwin.mapper.CIndcompetTradeMapper;
import com.sofwin.mapper.CRelatedpartyMapper;
import com.sofwin.pojo.*;
import com.sofwin.service.contents.HorizontalCompetitionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: ssm-parent
 * @description: 同行竞争和关联交易
 * @author: Mr.jhx
 * @create: 2021-04-27 10:54
 * @Version 1.0
 **/
@Service
public class HorizontalCompetitionServiceImpl implements HorizontalCompetitionService {
    @Autowired
    private CIndcompetTradeMapper indcompetTradeMapper;
    @Autowired
    private CRelatedpartyMapper relatedpartyMapper;
    @Autowired
    private CBriefrelationshipMapper briefrelationshipMapper;
    @Autowired
    private HorizontalDto horizontalDto;
    @Override
    public HorizontalDto selecthorizontalByBusinessId(Integer companyId) {

        // 同业竞争信息
        CIndcompetTradeExample example = new CIndcompetTradeExample();
        CIndcompetTradeExample.Criteria criteria = example.createCriteria();
        criteria.andCompanyIdEqualTo(companyId);
        List<CIndcompetTrade> cIndcompetTrades = indcompetTradeMapper.selectByExampleWithBLOBs(example);

        horizontalDto.setIndcompetTrade(cIndcompetTrades.get(0));
        // 主要关联方及关联方关系信息
        CRelatedpartyExample examples = new CRelatedpartyExample();
        CRelatedpartyExample.Criteria criteria1 = examples.createCriteria();
        criteria1.andIndcompetTradeIdEqualTo(cIndcompetTrades.get(0).getId());
        List<CRelatedparty> cRelatedparties = relatedpartyMapper.selectByExample(examples);

        horizontalDto.setRelatedparty(cRelatedparties);
        // 关联方交易简要情况
        CBriefrelationshipExample exampless = new CBriefrelationshipExample();
        CBriefrelationshipExample.Criteria criteria2 = exampless.createCriteria();
        criteria2.andIndcompetTradeIdEqualTo(cIndcompetTrades.get(0).getId());
        List<CBriefrelationship> cBriefrelationships = briefrelationshipMapper.selectByExample(exampless);

        horizontalDto.setBriefrelationship(cBriefrelationships);
        return horizontalDto;
    }

}
